apiready = function(){
seajs.use(['../../V',"../../api","../../jquery","../../app","../../service"],function(V,$api,$,app,service){
	var vm = {
		el: '.container',
	  	data: {
				shopInfo: {},
				showList: [],
				classifyList: [],
				page: 1,
				hasMoreData: true
	  	},
	  	methods:{
	  		//--菜单展开
	  		navDown: function(et){
	  			var list = this.$refs.navDownList;
	  			var bg = this.$refs.navBg;
	  			bg.style.cssText += 'display: block';
	  			list.style.cssText += '-webkit-transform: translateY(0);transform: translateY(0);';
	  		},
	  		//--菜单收起
	  		navUp: function(et){
	  			var list = this.$refs.navDownList;
	  			var bg = this.$refs.navBg;
	  			list.style.cssText += '-webkit-transform: translateY(-100%);transform: translateY(-100%);';
	  			bg.style.cssText += 'display: none';
	  		},
				init: function () {
					// 获取拼团列表
					this.getGroupList();

					// 获取分类列表
					this.getClassifyIndex();
				},

				// 获取商品列表
				getGroupList: function () {
					var that = this;
					var arg;
					var page = this.page;
					var id = that.classfiyid;
					if (!id) {
						// 获取全部数据
						arg = {
							unionid: that.shopInfo.unionid,
							shop_code: that.shopInfo.shop_code,
							is_home: 0,
							page: page
						}
					} else {
						// 获取某一类商品
						arg = {
							unionid: that.shopInfo.unionid,
							shop_code: that.shopInfo.shop_code,
							category_id: id,
							page: page,
							is_home: 0
						}
					}

					app.ajax(
            service['getCollageList'],
            {
              data: {
                values:arg
              }
            },
            function (res) {
              if (res.code == 0) {
								if (that.page == 1) {
									that.showList = res.data;
								} else {
									if (res.data.length > 0) {
										for (var i = 0, len = res.data.length; i < len; i++) {
											that.showList.push(res.data[i]);
										}
										that.hasMoreData = true;
									} else {
										that.hasMoreData = false;
									}
								}
              } else {
                api.toast({
                    msg: res.message,
                    duration: 2000,
                    location: 'bottom'
                });
              }
            }
          );
				},

				// 获取分类列表
				getClassifyIndex: function () {
					var that = this;
					app.ajax(
						service['getclassifyList'],
						{
							data: {
								values: {
									unionid: that.shopInfo.unionid,
									shop_code: that.shopInfo.shop_code,
									is_home: 0,
									hot: 0
								}
							}
						},
						function (res) {
							if (res.code == 0) {
								that.classifyList = res.data;
							} else {
								api.toast({
										msg: res.message,
										duration: 2000,
										location: 'bottom'
								});
							}
						}
					);
				},

				// 切换分类
				selectClassify: function (idx,id) {
          var classfiyid = id;
					this.page = 1;
					this.showList = [];

          $('.type-nav').removeClass('active');
          $('.type-nav').eq(idx).addClass('active');
          if (id == -1) {
						this.classfiyid = 0;
						this.getGroupList();
          } else {
						this.classfiyid = id;
						this.getGroupList();
          }
				},

				// 触底
				scrolltobottom: function () {
					if (this.hasMoreData) {
						this.page+=1;
					}
					this.getGroupList();
				},

				// 拼团详情
				toGroupDetail: function (id) {
					var that = this;
					// groupBuyDetail
					app.openWin('groupBuyDetail',{goodsId :id}); // 拼团
				}
	  	},
	  	mounted:function() {

	  	},
	  	created: function(){
				var that = this;
				var shopInfo = api.pageParam.shopInfo;
				this.shopInfo = shopInfo;
				this.init();
				api.addEventListener({
			 	    name: 'scrolltobottom',
						extra:{
				        threshold:0  //设置距离底部多少距离时触发，默认值为0，数字类型
				    }
			 	}, function(ret, err){
						that.scrolltobottom()
			 	});
	  	}
	};
	var even = function() {}
	var newVue = new Vue(vm);
	even();
});
}
